package com.sgzn.sgpay.service.tcp.receive.handler;

import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.service.tcp.api.TcpQuerySignalAnswerService;
import com.sgzn.sgpay.service.tcp.model.terminal.request.TcpQuerySignalAnswerRequest;
import com.sgzn.sgpay.service.tcp.receive.TcpReceiveCallHandlerTemplate;
import com.sgzn.sgpay.service.tcp.receive.modle.TcpReceiveCallRequest;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 查询信号(终端发起) 处理器
 * @author huangsenguang
 * @version Id: TcpQuerySignalHandler.java, v 0.1 2018/7/30 15:01 huangsenguang Exp $$
 */
@Service
@Slf4j
public class TcpQuerySignalHandler extends TcpReceiveCallHandlerTemplate<Boolean> {
    /**
     * 协议总字符数
     */
    @Getter
    private final int protocolLength = 12;

    @Resource
    private TcpQuerySignalAnswerService tcpQuerySignalAnswerService;

    @Override
    public Boolean callInner(TcpReceiveCallRequest request) {
        return true;
    }

    /**
     * 处理后
     * @param request
     * @param result
     */
    @Override
    protected void handleAfter(TcpReceiveCallRequest request, Boolean result) {
        //TODO 查询信号(终端发起) 逻辑处理
        TcpQuerySignalAnswerRequest tcpRequest = new TcpQuerySignalAnswerRequest();
        tcpRequest.setDeviceId("10001");
        tcpRequest.setSignalValue("31");
        tcpRequest.setLinkServerState("0");
        SgsResultResponse<String> tcpResponse = tcpQuerySignalAnswerService.invoke(tcpRequest);

    }

    @Override
    protected int getProtocolLength(TcpReceiveCallRequest request) {
        return this.protocolLength;
    }
}

